#include "dataset_io.h"
#include "dataset_io_kitti.h"
#include "dataset_io_nclt.h"
#include "dataset_io_panoseq.h"
#include "dataset_io_panovideo.h"

namespace DatasetIO {

DatasetIoInterface::Ptr DatasetIoFactory::getDatasetIo(
    const std::string &dataset_type) {
    if (dataset_type == "panovideo") {
        return DatasetIoInterface::Ptr(new PanoVideoIO);
    } else if (dataset_type == "panoseq") {
        // return DatasetIoInterface::Ptr(new PanoSeqIO);
    } else if (dataset_type == "nclt") {
        return DatasetIoInterface::Ptr(new NcltIO);
    }
    //   else if (dataset_type == "bag") {
    //     return DatasetIoInterfacePtr(new RosbagIO);
    //    else if (dataset_type == "uzh") {
    //     return DatasetIoInterfacePtr(new UzhIO);
    else if (dataset_type == "kitti") {
        return DatasetIoInterface::Ptr(new KittiIO);
    } else {
        std::cerr << "Dataset type " << dataset_type << " is not supported"
                  << std::endl;
        std::abort();
    }
}

bool DatasetIoFactory::getNextMonoImage(
    DatasetIoInterface::Ptr dataset_interface,
    MonoImageData::Ptr &mono_image_data) {
    mono_image_data = nullptr;
    auto dataset = dataset_interface->get_data();

    if (dataset->type == DatasetType::kPanoVideo) {
        mono_image_data = dataset->get_next_mono_image_data();
    } else if (dataset->type == DatasetType::kPanoSeq) {
        mono_image_data = dataset->get_next_mono_image_data();
    } else if (dataset->type == DatasetType::kNclt) {
        mono_image_data = dataset->get_next_mono_image_data();
    } else if (dataset->type == DatasetType::kKitti) {
        mono_image_data = dataset->get_next_mono_image_data();
    }

    if (mono_image_data)  // TODO: 存疑
        return true;
    else
        return false;
}

bool DatasetIoFactory::getNextData(
    DatasetIoInterface::Ptr dataset_interface,
    std::vector<std::vector<Measurement::Ptr>> &all_datas) {
    auto dataset = dataset_interface->get_data();
    if (dataset->type == DatasetType::kNclt) {
        all_datas = dataset->get_nearest_data();
        return true;
    }

    return false;
}

}  // namespace DatasetIO
